﻿using System;
using System.ComponentModel.Composition;
using System.Diagnostics;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Utilities;
using System.Windows;

namespace CodeJumper
{
    [ContentType("text"), Export(typeof(IMouseProcessorProvider)), Name("CodeJumpMouseProcessor"), TextViewRole(PredefinedTextViewRoles.Interactive)]
    internal sealed class MouseProcessorProvider : IMouseProcessorProvider
    {
        public IMouseProcessor GetAssociatedProcessor(IWpfTextView wpfTextView)
        {
            Func<MouseProcessor> creator = null;
            try
            {
                if (creator == null)
                {
                    creator = delegate
                    {
                        return new MouseProcessor(wpfTextView);
                    };
                }
                return wpfTextView.Properties.GetOrCreateSingletonProperty<MouseProcessor>(creator);
            }
            catch (Exception)
            {
                return null;
            }

        }
    }
}
